package cn.bdqn.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bdqn.pojo.User;
import cn.bdqn.service.UserService;

@Controller
@RequestMapping("/user")
public class UserController {
	
	@Resource
	private UserService userService;

	//跳转到登陆页面
	@RequestMapping("/toLogin")
	public String toLogin() {
		return "login";
	}
	
	//登陆
	@RequestMapping("/doLogin")
	public String doLogin(User user,HttpSession session) {
		User _user = userService.get(user.getUserCode());
		if(_user!=null) {
			if(_user.getUserPassword().equals(user.getUserPassword())) {
				session.setAttribute("userSession", _user);
				return "redirect:/user/main/index";
			}else {
				return "login";
			}
		}else {
			return "login";
		}
		
	}
	
	//首页面
	@RequestMapping("/main/index")
	public String index() {
		return "main/index";
	}
	
}
